

use "$data/clean/clean_main_complete.dta" , replace


tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 6

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear



gen pana=.
gen panb=.
gen panc=.
gen pand=.
gen pane=.
gen intt= .
gen empt =. 
gen part_aff = .

label var pana "\underline{Individual level characteristics} " 
label var panb "\underline{Prior experience} " 

label var empt " "
  
  foreach yvar of varlist pana  female age member member_years voice_prior  z_votes_own z_votes_other_1 z_votes_other_2 ///
 empt panb d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others empt {
	qui sum `yvar', d
	if `r(N)'!=0 {
	qui sum `yvar' if  control ==1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	
	qui sum `yvar' if voice_instrumental ==1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col2
	
	qui sum `yvar' if voice_feedback_instrumental ==1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col3
	
	qui sum `yvar' if voice_intrinsic==1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col4
	
	qui sum `yvar' if voice_feedback_intrinsic ==1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col5
	
	reg `yvar' voice_instrumental voice_intrinsic voice_feedback_intrinsic voice_feedback_instrumental , r
	test voice_instrumental voice_intrinsic voice_feedback_intrinsic voice_feedback_instrumental

	
	cap: estadd loc thisstat`count' = string(r(p), "%9.2f"): col6

	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1
}

  

/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"

esttab col* using "$output/balance_detailed_main", booktabs cells(none) nonum nogap mtitle("Control" "Instrumental" "Instrumental + Feedback" "Intrinsic" "Intrinsic + Feedback" "p-value joint significance") ///
 stats(`statnames', labels(`varlabels'))  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear




